/*
package com.hutu.picture.aop;

import cn.dev33.satoken.stp.StpUtil;
import com.hutu.mianshiya.annotation.AiCheck;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.redisson.api.RRateLimiter;
import org.redisson.api.RateType;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AiCheckAspect {

    @Autowired
    private RedissonClient redissonClient;

    @Around("@annotation(aiCheck)")
    public Object checkUsage(ProceedingJoinPoint joinPoint, AiCheck aiCheck) throws Throwable {
        String userId = StpUtil.getLoginIdAsString(); // 根据实际情况获取用户ID
        RRateLimiter rateLimiter = redissonClient.getRateLimiter(userId);
        rateLimiter.trySetRate(RateType.OVERALL, aiCheck.limit(), aiCheck.timeWindow(), aiCheck.timeUnit());
        if (rateLimiter.tryAcquire()) {
            return joinPoint.proceed();
        } else {
            throw new RuntimeException("请稍后再使用");
        }
    }
}*/
